package cn.erhu.designPattern.headFirst.observer_2;

import cn.erhu.designPattern.headFirst.observer.DisplayElement;

import java.util.Observable;
import java.util.Observer;

/**
 * #请替换掉这里的东东#
 * <p/>
 * User: erhu
 * Date: 13-5-20
 * Time: 上午7:46
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {

    Observable observable;
    private float temperature;
    private float humidity;

    public CurrentConditionsDisplay(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println("Current conditions: " + temperature
                + "F degrees and " + humidity + "% humidity");
    }

    @Override
    public void update(Observable observable, Object arg) {
        if (observable instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) observable;
            this.temperature = weatherData.getTemperature();
            this.humidity = weatherData.getHumidity();
            display();
        }
    }
}
